﻿Public Class NguoiDangTinDAO

    Private connect As ConnectDB
    Private sqlstr As String


    Public Sub New()
        connect = New ConnectDB()
    End Sub

    Public Function IsUpNDT(ByVal emp As NguoiDangTinDTO, ByVal flag As Boolean)
        Dim Madt As String = emp.Mã_đăng_tin
        Dim Hoten As String = emp.Họ_tên
        Dim Email As String = emp.Email
        Dim Dienthoai As String = emp.Điện_thoại
        Dim Diachi As String = emp.Địa_chỉ
        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT NGUOIDANGTIN (HoTen, Email, DienThoai, DiaChi)" & _
                        " VALUES('" & Hoten & "', '" & Email & "', '" & _
                                        Dienthoai & "', '" & Diachi & "')"
        Else
            sqlstr = "UPDATE NGUOIDANGTIN SET  HoTen  = '" & Hoten & _
                                        "', Email   = '" & Email & _
                                        "', DienThoai      = '" & Dienthoai & _
                                        "',  DiaChi      = '" & Diachi & _
                                    "' WHERE MaDangTin  = '" & Madt & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function

    Public Function DeleteNDT(ByVal emp As NguoiDangTinDTO)
        Dim Madt As String = emp.Mã_đăng_tin
        sqlstr = "DELETE NGUOIDANGTIN WHERE MaDangTin = '" & Madt & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function Getdata() As List(Of NguoiDangTinDTO)
        Dim i As Integer
        Dim id, pw, ht, ns, gt As String
        Dim emp As NguoiDangTinDTO
        Dim empLst As New List(Of NguoiDangTinDTO)
        Dim dt As New DataTable
        dt = connect.GetData("Select * From NGUOIDANGTIN")

        For i = 0 To dt.Rows.Count() - 1
            id = dt.Rows(i)("MaDangTin").ToString
            pw = dt.Rows(i)("HoTen").ToString
            ht = dt.Rows(i)("Email").ToString
            ns = dt.Rows(i)("DienThoai").ToString
            gt = dt.Rows(i)("Diachi").ToString
            emp = New NguoiDangTinDTO(id, pw, ht, ns, gt)
            empLst.Add(emp)
        Next
        Return empLst
    End Function



End Class
